package com.mall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.db.domain.Feedback;
import com.mall.db.service.FeedbackService;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/feedback/fc")
public class FeedbackController extends BaseController<Feedback>{
    @Resource(name="feedbackService")
    private FeedbackService fs;


    @Override
    public Map<String, Object> find(Feedback feedback) {
        //实现分页
        PageHelper.startPage(feedback.getPage(),feedback.getLimit());

        QueryWrapper<Feedback> qw = new QueryWrapper<>();
        if (!StringUtils.isEmpty(feedback.getId())){
            qw.eq("id",feedback.getId());
        }if (!StringUtils.isEmpty(feedback.getUser())){
            qw.eq("user",feedback.getUser());
        }
        List<Feedback> list = fs.list(qw);

        PageInfo<Feedback> page = new PageInfo<>(list,feedback.getLimit());

        return this.findMap(page.getList(), page.getTotal());
    }

    @Override
    public Map<String, Object> add(Feedback feedback) {
        //TODO 密码加密
        boolean b = fs.save(feedback);
        return this.iud("新增",b,feedback);
    }

    @Override
    public Map<String, Object> update(Feedback feedback) {
        boolean b = fs.updateById(feedback);
        return this.iud("编辑",b,feedback);
    }
    @Override
    public Map<String, Object> delete(Feedback feedback) {
        boolean b = fs.removeById(feedback);
        return this.iud("删除",b,feedback);
    }
}
